package com.von.nhcf.constant;

import java.util.HashSet;
import java.util.Set;

public class AccessIgnoreResources {
    public static final Set<String> PASS_RES_SET = new HashSet<>();

    static {
        PASS_RES_SET.add("/");
        PASS_RES_SET.add("/member/auth/do/logout");
        PASS_RES_SET.add("/member/auth/to/login/page");
        PASS_RES_SET.add("/member/auth/do/login");
        PASS_RES_SET.add("/member/auth/do/submit");
        PASS_RES_SET.add("/member/auth/send/sms/page");
        PASS_RES_SET.add("/member/auth/to/register/page");
    }

    public static final Set<String> STATIC_RES_SET = new HashSet<>();

    static {
        STATIC_RES_SET.add("bootstrap");
        STATIC_RES_SET.add("css");
        STATIC_RES_SET.add("fonts");
        STATIC_RES_SET.add("img");
        STATIC_RES_SET.add("jquery");
        STATIC_RES_SET.add("layer");
        STATIC_RES_SET.add("script");
        STATIC_RES_SET.add("ztree");
    }

    public static boolean judgeCurrentServletPath(String servletPath) {
        if (servletPath == null || servletPath.length() == 0) {
            throw new RuntimeException("当前路径的不存在或字符串长度为0");
        }
        String[] split = servletPath.split("/");
        // 分割后的数组应该大于2
        int minLen = 2;
        if (split.length < minLen) {
            return false;
        }
        // split在以'/'作为分隔符时，会保留'/'前的内容，即一个空字符串
        String firstLevel = split[1];
        return STATIC_RES_SET.contains(firstLevel);
    }
}
